package com.ls.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.string.StringDecoder;

import java.nio.charset.Charset;

public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //获得管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        //添加一个解码器 HttpServerCodec 是netty提供的编码解码器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
//        pipeline.addLast(new StringDecoder(Charset.forName("UTF-8")));
        pipeline.addLast("MyTestHttpServerHandler", new TestHttpServerHandler());
    }
}
